home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / CD-Rom Drive you crazy / Source / CDTrayControl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-26  |  1.6 KB  |  78 lines  |  [TEXT/CWIE]

  1. #include "CDTrayControl.h"
  2. #include "PO_Globals.h"
  3. #include <ata.h>
  4. #include "PO_Assert.h"
  5. #include <string.h>
  6.  
  7. static bool                gActiveQ = false;
  8. static bool                gDoneQ = false;
  9. static ataPB            gPB;
  10. static ATAPICmdPacket    gPacket;
  11.  
  12. static pascal void _CompleteProc(ataPB*    pb)
  13. {
  14.     PO_EnterCallback();
  15.  
  16.     gDoneQ = true;
  17.  
  18.     PO_ExitCallback();
  19. }
  20.  
  21. void    StartTrayCycle()
  22. {
  23.     if(not gActiveQ){
  24.         gActiveQ = true;
  25.         
  26.         memset(&gPB,0,sizeof(gPB));
  27.         memset(&gPacket,0,sizeof(gPacket));
  28.         
  29.         gPB.ataIOParamBlock.ataPBVers = 3;
  30.         gPB.ataIOParamBlock.ataPBFunctionCode = 1;
  31.         gPB.ataIOParamBlock.ataPBIOSpeed = 4;
  32.         gPB.ataIOParamBlock.ataPBFlags = 0x8021;
  33.         gPB.ataIOParamBlock.ataPBDeviceID = 1;
  34.         gPB.ataIOParamBlock.ataPBTimeOut = 0x2710;
  35.         gPB.ataIOParamBlock.ataPBCallbackPtr = (ProcPtr)_CompleteProc;
  36.         gPB.ataIOParamBlock.ataPBClientPtr1 = LMGetCurrentA5();
  37.  
  38.         gPB.ataIOParamBlock.ataPBStatusRegister = 0x50;
  39.         gPB.ataIOParamBlock.ataPBLogicalBlockSize = 0x200;
  40.  
  41.         gPB.ataIOParamBlock.ataPBActualTxCount = 0x12;
  42.         
  43.         gPB.ataIOParamBlock.ataPBTaskFile.ataTFSDH = 0xA0;
  44.         gPB.ataIOParamBlock.ataPBTaskFile.ataTFCommand = 0xA0;
  45.         gPB.ataIOParamBlock.ataPBPacketPtr = &gPacket;
  46.         
  47.         gPacket.atapiPacketSize = 12;
  48.         gPacket.atapiCommandByte[0] = 0x1b00;
  49.         gPacket.atapiCommandByte[2] = 0x0200;
  50.         
  51.         PO_PrepareCallback();
  52.         
  53.         gDoneQ = false;
  54.         ataManager(&gPB);
  55.     }
  56. }
  57.  
  58. void    IdleTray()
  59. {
  60.     if(gActiveQ){
  61.         if(gDoneQ){
  62.             if(gPacket.atapiCommandByte[2] == 0x0200){
  63.                 gPacket.atapiCommandByte[2] = 0x0300;
  64.             }else{
  65.                 gPacket.atapiCommandByte[2] = 0x0200;
  66.             }
  67.             gDoneQ = false;
  68.             ataManager(&gPB);
  69.         }
  70.     }
  71. }
  72.  
  73. void    StopTrayCycle()
  74. {
  75.     gActiveQ = false;
  76. }
  77.  
  78.